@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"

set PROJECT_PATH="%TAO_ROOT%/orbsvcs/tests/FT_App"

cd %PROJECT_PATH%


@echo off
setlocal

:: 定义要删除的文件列表
set "files=*.ior"

:: 删除文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)


@REM 启动命名服务
start "tao_cosnaming" cmd /k "%TAO_ROOT%/orbsvcs/Naming_Service/tao_cosnaming -ORBdebuglevel -o %PROJECT_PATH%/ns.ior -m 1"
timeout /t 3

@REM 启动复制管理器 -n 指定绑定到命名服务的名称
start "tao_ft_replicationmanager" cmd /k "%TAO_ROOT%/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o %PROJECT_PATH%/rm.ior -ORBEndpoint iiop://OMEN_2023:16287  -n ReplicationManager"
timeout /t 4

@REM 启动故障检测器
echo "==>Start tao_fault_notifier"
start "tao_fault_notifier" cmd /k "%TAO_ROOT%/orbsvcs/Fault_Notifier/tao_fault_notifier -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:16287/ReplicationManager -o %PROJECT_PATH%/notifier.ior -q"
timeout /t 5

@REM 启动故障通知器,注册到 复制管理器上
echo "==>Start tao_fault_detector"
start "tao_fault_detector" cmd /k "%TAO_ROOT%/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:16287/ReplicationManager -o %PROJECT_PATH%/detector.ior -q"
timeout /t 5

@REM =======================

echo "==>Start ft_replica1"
start "ft_replica1" cmd /k "ft_replica -o %PROJECT_PATH%/factory1.ior -f none -t %PROJECT_PATH%/replica1.ior -l loc1 -i type1 -q -p %PROJECT_PATH%/persistent.dat"
timeout /t 4

echo "==>Start ft_replica2"
start "ft_replica2" cmd /k "ft_replica -o %PROJECT_PATH%/factory2.ior -f none -t %PROJECT_PATH%/replica2.ior -l loc2 -i type1 -q -p %PROJECT_PATH%/persistent.dat" 
timeout /t 4

echo "==>Start ft_client"
start "ft_client" cmd /k "ft_client -f file://%PROJECT_PATH%/replica1.ior -f file://%PROJECT_PATH%/replica2.ior -c testscript"

@REM pause >nul
@echo off





